<include file="Common/header" />
<title>新建网站角色</title>
</head>
<body>
<div class="pd-20">
	<form action="" method="post" class="form form-horizontal" id="form-user-character-add">
		<div class="panel panel-primary">
			<div class="panel-header">活动基本信息</div> 
			<div class="panel-body">
				<div class="row cl">
					<label class="form-label col-3"><span class="c-red">* </span>活动名称：</label>
					<div class="formControls col-8">
						<input type="text" class="input-text radius" value="{$info['type_title']}" placeholder="" id="type_title" name="type_title" />
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-3"><span class="c-red">* </span>开始时间：</label>
					<div class="formControls col-3">
						<span class="select-box radius">
							<input class="select form-control layer-date radius" placeholder="" id="type_btime" name="type_btime" value="{$info['typeid'] ? $info['type_btime']|date='Y-m-d',### : ''}" />
						</span>
					</div>
					<label class="form-label col-2"><span class="c-red">* </span>结束时间：</label>
					<div class="formControls col-3">
						<span class="select-box radius">
							<input class="select form-control layer-date radius" placeholder="" id="type_etime" name="type_etime" value="{$info['typeid'] ? $info['type_etime']|date='Y-m-d',### : ''}" />
						</span>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-3"><span class="c-red">* </span>享受活动合同号：</label>
					<div class="formControls col-8">
						<textarea class="textarea radius" placeholder="合同号之间请使用|分隔" id="contract" name="contract">{$info['contract']}</textarea>
					</div>
				</div>
			</div>
		</div>
		<input type="hidden" id="typeid" name="typeid" value="{$info['typeid']}" />
		<div class="panel panel-warning">
			<div class="panel-header">活动规则</div>
			<div class="panel-body">
				<div class="row cl">
					<table class="table table-border table-bordered table-bg">
						<thead>
							<tr class="text-c">
								<th>房型</th>
								<th>条件(月)</th>
								<th>房租减免(月)</th>
								<th>折扣比例(%)</th>
								<th>物业减免(月)</th>
								<th>折扣比例(%)</th>
								<th>水电补助(元)</th>
								<th width="70"></th>
							</tr>
						</thead>
						<tbody class="ntbody">
							<?php if(is_array($attrlist) && count($attrlist)){ ?>
							<?php foreach($attrlist as $k=>$attr){ ?>
							<tr class="text-c">
								<td>
									<span class="select-box radius" style="width: 70px;">
										<select class="select" id="param[{$k}][room_type]" name="param[{$k}][room_type]">
											<option value="D1" {$attr['room_type'] == 'D1' ? 'selected' : ''}>D1</option>
											<option value="D2" {$attr['room_type'] == 'D2' ? 'selected' : ''}>D2</option>
											<option value="D3" {$attr['room_type'] == 'D3' ? 'selected' : ''}>D3</option>
											<option value="D4" {$attr['room_type'] == 'D4' ? 'selected' : ''}>D4</option>
											<option value="D5" {$attr['room_type'] == 'D5' ? 'selected' : ''}>D5</option>
										</select>
									</span>
								</td>
								<td>
									<span class="select-box radius" style="width: 80px;">
										<select class="select" id="param[{$k}][symbol]" name="param[{$k}][symbol]">
											<option value="0" {$attr['symbol'] == 0 ? 'selected' : ''}>小于</option>
											<option value="1" {$attr['symbol'] == 1 ? 'selected' : ''}>等于</option>
											<option value="2" {$attr['symbol'] == 2 ? 'selected' : ''}>大于</option>
											<!--
											<option value="3">&lt;＝</option>
											<option value="4">&gt;=</option>-->
										</select>
									</span>
									<span class="select-box radius" style="width: 50px;">
										<select class="select" id="param[{$k}][attr_month]" name="param[{$k}][attr_month]">
											<?php for($i=0;$i<=12;$i++){ ?>
											<option value="{$i}" {$attr['attr_month'] == $i ? 'selected' : ''}>{$i}</option>
											<?php } ?>
										</select>
									</span>
								</td>
								<td>
									<span class="select-box radius" style="width: 50px;">
										<select class="select" id="param[{$k}][rent_count]" name="param[{$k}][rent_count]">
											<?php for($i=0;$i<=12;$i++){ ?>
											<option value="{$i}" {$attr['rent_count'] == $i ? 'selected' : ''}>{$i}</option>
											<?php } ?>
										</select>
									</span>
								</td>
								<td>
									<span class="select-box radius" style="width: 80px;">
										<select class="select" id="param[{$k}][rent_multiple]" name="param[{$k}][rent_multiple]">
											<?php for($i=0;$i<10;$i++){ ?>
											<option value="{$i/10}" {$attr['rent_multiple'] == $i/10 ? 'selected' : ''}>
												<?php echo $i*10 == 0 ? '全免' : ($i*10) .'%'; ?>
											</option>
											<?php } ?>
										</select>
									</span>
								</td>
								<td>
									<span class="select-box radius" style="width: 50px;">
										<select class="select" id="param[{$k}][property_count]" name="param[{$k}][property_count]">
											<?php for($i=0;$i<=12;$i++){ ?>
											<option value="{$i}" {$attr['property_count'] == $i ? 'selected' : ''}>{$i}</option>
											<?php } ?>
											<option value="-1" {$attr['property_count'] == -1 ? 'selected' : ''}>全租期</option>
										</select>
									</span>
								</td>
								<td>
									<span class="select-box radius" style="width: 80px;">
										<select class="select" id="param[{$k}][property_multiple]" name="param[{$k}][property_multiple]">
											<?php for($i=0;$i<10;$i++){ ?>
											<option value="{$i/10}" {$attr['property_multiple'] == $i/10 ? 'selected' : ''}>
												<?php echo $i*10 == 0 ? '全免' : ($i*10) .'%'; ?>
											</option>
											<?php } ?>
										</select>
									</span>
								</td>
								<td>
									<input class="input-text radius" name="param[{$k}][other]" value="{$attr['other']}" style="width: 50px;" />
								</td>
								<?php if($k > 0){ ?>
								<td>
									<a title="移除" href="javascript:void(0);" class="btn btn-danger radius deleteBtns" style="height: 30px;" onclick="delLine(this);"><i class="Hui-iconfont">&#xe6a1;</i></a>
								</td>
								<?php }else{ ?>
								<td></td>
								<?php } ?>
							</tr>
							<?php } ?>
							<?php }else{ ?>
							<tr class="text-c">
								<td>
									<span class="select-box radius" style="width: 70px;">
										<select class="select" id="param[0][room_type]" name="param[0][room_type]">
											<option value="D1" {$info['room_type'] == 'D1' ? 'selected' : ''}>D1</option>
											<option value="D2" {$info['room_type'] == 'D2' ? 'selected' : ''}>D2</option>
											<option value="D3" {$info['room_type'] == 'D3' ? 'selected' : ''}>D3</option>
											<option value="D4" {$info['room_type'] == 'D4' ? 'selected' : ''}>D4</option>
											<option value="D5" {$info['room_type'] == 'D5' ? 'selected' : ''}>D5</option>
										</select>
									</span>
								</td>
								<td>
									<span class="select-box radius" style="width: 80px;">
										<select class="select" id="param[0][symbol]" name="param[0][symbol]">
											<option value="0">小于</option>
											<option value="1">等于</option>
											<option value="2">大于</option>
											<!--
											<option value="3">&lt;＝</option>
											<option value="4">&gt;=</option>-->
										</select>
									</span>
									<span class="select-box radius" style="width: 50px;">
										<select class="select" id="param[0][attr_month]" name="param[0][attr_month]">
											<?php for($i=0;$i<=12;$i++){ ?>
											<option value="{$i}">{$i}</option>
											<?php } ?>
										</select>
									</span>
								</td>
								<td>
									<span class="select-box radius" style="width: 50px;">
										<select class="select" id="param[0][rent_count]" name="param[0][rent_count]">
											<?php for($i=0;$i<=12;$i++){ ?>
											<option value="{$i}">{$i}</option>
											<?php } ?>
										</select>
									</span>
								</td>
								<td>
									<span class="select-box radius" style="width: 80px;">
										<select class="select" id="param[0][rent_multiple]" name="param[0][rent_multiple]">
											<option value="0">全免</option>
											<option value="0.9">90%</option>
											<option value="0.8">80%</option>
											<option value="0.7">70%</option>
											<option value="0.6">60%</option>
											<option value="0.5">50%</option>
											<option value="0.4">40%</option>
											<option value="0.3">30%</option>
											<option value="0.2">20%</option>
											<option value="0.1">10%</option>
										</select>
									</span>
								</td>
								<td>
									<span class="select-box radius" style="width: 50px;">
										<select class="select" id="param[0][property_count]" name="param[0][property_count]">
											<?php for($i=0;$i<=12;$i++){ ?>
											<option value="{$i}">{$i}</option>
											<?php } ?>
											<option value="-1" {$attr['property_count'] == -1 ? 'selected' : ''}>全租期</option>
										</select>
									</span>
								</td>
								<td>
									<span class="select-box radius" style="width: 80px;">
										<select class="select" id="param[0][property_multiple]" name="param[0][property_multiple]">
											<option value="0">全免</option>
											<option value="0.9">90%</option>
											<option value="0.8">80%</option>
											<option value="0.7">70%</option>
											<option value="0.6">60%</option>
											<option value="0.5">50%</option>
											<option value="0.4">40%</option>
											<option value="0.3">30%</option>
											<option value="0.2">20%</option>
											<option value="0.1">10%</option>
										</select>
									</span>
								</td>
								<td>
									<input class="input-text radius" id="param[0][other]" name="param[0][other]" value="" style="width: 50px;" />
								</td>
								<td></td>
							</tr>
							<?php } ?>
						</tbody>	
					</table>
					
					<table class="table table-border table-bordered pt-5">
						<tr class="text-c">
							<td>
								<button type="button" class="btn btn-primary radius"><i class="icon-ok"></i> 添加一行</button>
								<button type="button" class="btn btn-success radius"><i class="icon-ok"></i> 确定</button>
							</td>
						</tr>
					</table>
				</div>
			</div>
		</div>
	</form>
</div>

<script>
	function delLine(obj){
		$(obj).closest('tr').remove();
	}
	
	$(function(){
		$(".layer-date").on('click', function(){
			laydate({istime: true, format: 'YYYY-MM-DD'});
		});
		
		var line = '{$attrcount}';
		//添加一行
		$(".btn-primary").on('click', function(){
			var html = $(".ntbody tr:eq(0)").html();
			var remove = '<a title="移除" href="javascript:void(0);" class="btn btn-danger radius deleteBtns" style="height: 30px;" onclick="delLine(this);"><i class="Hui-iconfont">&#xe6a1;</i></a>';
			//替换全部参数
			html = html.replace(/param\[(0)\]/g, 'param['+ line/1 +']');
			//替换
			html = html.replace('<td></td>', '<td>'+ remove +'</td>');
			//追加规则栏
			$(".ntbody").append('<tr class="text-c">' + html + '</tr>');
			//规则计数
			line = line/1 + 1;
		});
		
		//提交数据
		$(".btn-success").on('click', function(){
			var title = $("#type_title").val() || "";
			if(title.length <= 0){
				layer.msg('请输入收费类型名', {icon:5, time: 2000});
				return false;
			}
			
			if($("#type_btime").val() == ""){
				layer.msg('请选择开始时间', {icon:5, time: 2000});
				return false;
			}
			
			if($("#type_etime").val() == ""){
				layer.msg('请选择结束时间', {icon:5, time: 2000});
				return false;
			}

			//等待效果
			var load = layer.load(2);
			$.post('add.html', $("#form-user-character-add").serialize(), function(msg){
				layer.close(load);
				if(msg == '编辑成功'){
					layer.msg(msg, {icon: 1, time: 2000}, function(){
						window.parent.location.reload(); //刷新
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
						parent.layer.close(index);
					});
				}else{
					layer.msg(msg, {icon: 0, time: 2000});
				}
			});
		});
	});
</script>
</body>
</html>